package com.ss.android.article.base.feature.detail2.video.a;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.account.Spipe;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.detail2.view.NewDetailActivity;
import com.ss.android.article.base.feature.detail2.view.NewVideoDetailActivity;
import com.ss.android.article.base.feature.detail2.widget.RelatedNewsHolder;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.ui.DrawableButton;
import com.ss.android.article.base.utils.ArticleHelper;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.NetworkStatusMonitor;
import com.ss.android.image.AsyncImageView;
import com.ss.android.image.loader.ImageLoader;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.j.ClickableBackgroundCompat;
import com.ss.android.newmedia.a.AdsAppBaseActivity;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONException;
import org.json.JSONObject;

public class e {
    public static int a;
    private static int[] l;

    static {
        l = new int[]{17, 16, 18, 19};
        a = 2;
    }

    public final int h;
    private final View.OnClickListener K;
    public View b;
    public DrawableButton c;
    public DrawableButton d;
    public TextView e;
    public Article f;
    public Context g;
    public int i;
    String j;
    String k;
    private NetworkStatusMonitor A;
    private int B;
    private int C;
    private ImageLoader D;
    private ImageLoader E;
    private boolean F;
    private boolean G;
    private long H;
    private int I;
    private TextView J;
    private TextView m;
    private ImageView n;
    private View o;
    private NightModeAsyncImageView p;
    private NightModeAsyncImageView q;
    private NightModeAsyncImageView r;
    private ViewGroup s;
    private NightModeAsyncImageView t;
    private NightModeAsyncImageView u;
    private TextView v;
    private ImageView w;
    private ImageView[] x;
    private AppData y;
    private Resources z;

    public e(Context arg2, NetworkStatusMonitor arg3, ImageLoader arg4, ImageLoader arg5, int arg6, int arg7, int arg8, int arg9) {

        this.F = false;
        this.G = false;
        this.K = new f(this);
        this.g = arg2;
        this.A = arg3;
        Spipe.inst();
        this.y = AppData.getInstance();
        this.F = AppData.isNightMode();
        this.z = arg2.getResources();
        this.h = arg6;
        this.i = arg7;
        this.C = arg8;
        this.B = arg9;
        this.D = arg4;
        this.E = arg5;
    }

    public static boolean a(View arg9, Article arg10, String position) {
        boolean v0;
        if (!AppData.getInstance().getAbSettings().isRelatedNewsJumpToTT()) {
            v0 = false;
        } else {
            String scheme = "";
            if (!TextUtils.isEmpty(arg10.openPageUrl) || !TextUtils.isEmpty(arg10.openUrl)) {
                scheme = arg10.openPageUrl;
                if ((TextUtils.isEmpty(((CharSequence) scheme))) || !scheme.startsWith("snssdk")) {
                    scheme = arg10.openUrl;
                }

                if (!TextUtils.isEmpty(((CharSequence) scheme)) && (scheme.startsWith("snssdk"))) {
                } else {
                    scheme = "";
                }
            }

            if (TextUtils.isEmpty(((CharSequence) scheme))) {
                scheme = "snssdk143://detail?groupid=" + arg10.groupId + "&item_id=" + arg10.itemId + "&aggr_type=" + arg10.aggrType + "&enter_from=lemon_browser";
            }

            if (android.support.design.a.a(arg9.getContext(), new Intent("android.intent.action.VIEW", Uri.parse(scheme)))) {
                AppUtil.b(arg9.getContext(), scheme);
                RelatedNewsHolder.reportJumpToTT(scheme, position);
                return true;
            }

            if (android.support.design.a.a(arg9.getContext(), new Intent("android.intent.action.VIEW", Uri.parse(scheme.replaceFirst("snssdk143", "snssdk35"))))) {
                AppUtil.b(arg9.getContext(), scheme.replaceFirst("snssdk143", "snssdk35"));
                RelatedNewsHolder.reportJumpToTT(scheme, position);
                return true;
            }

            v0 = false;
        }

        return v0;
    }

    private static ImageInfo a(ImageView arg3) {
        ImageInfo v0_1;
        ImageInfo v1 = null;
        if (arg3 == null || arg3.getVisibility() != View.VISIBLE) {
            v0_1 = v1;
        } else {
            Object v0 = arg3.getTag(com.ss.android.article.browser.R.id.image_info);
            if ((v0 instanceof ImageInfo)) {
                return (ImageInfo) v0;
            } else {
                v0_1 = v1;
            }
        }

        return v0_1;
    }

    private static void a(ImageView arg1, int arg2, int arg3) {
        ViewGroup.LayoutParams v0 = arg1.getLayoutParams();
        if (v0 != null) {
            if (arg2 > 0) {
                v0.width = arg2;
            }

            if (arg3 > 0) {
                v0.height = arg3;
            }

            arg1.setLayoutParams(v0);
        }
    }

    private static void a(NightModeAsyncImageView arg2, ImageInfo arg3) {
        android.support.design.a.setImage(((AsyncImageView) arg2), arg3);
        if (arg3 == null || arg3.mKey == null) {
            arg2.setTag(null);
            UIUtils.setVisibility(((View) arg2), 4);
        } else {
            UIUtils.setVisibility(((View) arg2), 0);
            arg2.setEnabled(true);
            arg2.setTag(com.ss.android.article.browser.R.id.image_info, arg3);
            Drawable v0 = arg2.getBackground();
            if (v0 != null) {
                v0.setLevel(0);
            }
        }
    }

    protected void a() {
        Object v6 = null;
        int v5 = R.id.image_info;
        ImageInfo v0 = a(this.t);
        if (v0 != null && this.E != null) {
            this.E.loadImage(this.t, v0, false);
        }

        if (this.D != null && this.o.getVisibility() == View.VISIBLE && this.x != null) {
            int v0_1;
            for (v0_1 = 0; v0_1 < 3; ++v0_1) {
                ImageInfo v2 = a(this.x[v0_1]);
                if (v2 != null) {
                    this.D.loadImage(this.x[v0_1], v2, false);
                }
            }
        }

        if (this.D != null) {
            v0 = a(this.u);
            if (v0 != null) {
                this.D.loadImage(this.u, v0, false);
            }
        }

        this.p.setTag(v5, v6);
        this.q.setTag(v5, v6);
        this.r.setTag(v5, v6);
        this.u.setTag(v5, v6);
        this.t.setTag(v5, v6);
    }

    public void a(View arg4) {
        this.b = arg4.findViewById(com.ss.android.article.browser.R.id.root);
        this.n = arg4.findViewById(com.ss.android.article.browser.R.id.divider);
        this.m = arg4.findViewById(com.ss.android.article.browser.R.id.title);
        this.s = arg4.findViewById(com.ss.android.article.browser.R.id.large_image_layout);
        this.t = arg4.findViewById(com.ss.android.article.browser.R.id.large_image);
        this.u = arg4.findViewById(com.ss.android.article.browser.R.id.right_image);
        this.c = arg4.findViewById(com.ss.android.article.browser.R.id.right_video_time);
        this.d = arg4.findViewById(com.ss.android.article.browser.R.id.large_video_time);
        this.J = arg4.findViewById(com.ss.android.article.browser.R.id.a6i);
        this.v = arg4.findViewById(com.ss.android.article.browser.R.id.video_source);
        this.e = arg4.findViewById(com.ss.android.article.browser.R.id.comment_count);
        this.w = arg4.findViewById(com.ss.android.article.browser.R.id.right_video_icon);
        this.o = arg4.findViewById(com.ss.android.article.browser.R.id.multi_image_layout);
        this.p = arg4.findViewById(com.ss.android.article.browser.R.id.item_image_0);
        this.q = arg4.findViewById(com.ss.android.article.browser.R.id.item_image_1);
        this.r = arg4.findViewById(com.ss.android.article.browser.R.id.item_image_2);
        a(this.p, this.h, this.i);
        a(this.q, this.h, this.i);
        a(this.r, this.h, this.i);
        a(this.u, this.h, this.i);
        this.x = new ImageView[3];
        this.x[0] = this.p;
        this.x[1] = this.q;
        this.x[2] = this.r;
        this.b.setOnClickListener(this.K);
    }

    public void a(Article arg7, long arg8, int arg10) {
        if (arg7 != null && arg7.groupId > 0) {
            this.f = arg7;
            this.H = arg8;
            this.I = arg10;
            this.b();
            this.c();
            this.d();
            this.f();
            this.e();
            if (this.I == a) {
                this.b.setPadding(0, this.b.getPaddingTop(), 0, this.b.getPaddingBottom());
                this.c.setDrawable((Drawable) null, false);
            }
        }
    }

    protected final void b() {
        long v6 = 0;
        int v4 = 3;
        if (this.f != null) {
            if (this.f.tags == null || (this.f.tags.isEmpty())) {
                this.m.setText(this.f.title);
            } else {
                this.m.setText(android.support.design.a.a(this.f.title, this.f.tags, this.z.getColor(com.ss.android.article.browser.R.color.update_comment_more_text_selector)));
            }

            TextView v1 = this.m;
            boolean v0 = this.f.clickTimestamp <= v6 ? true : false;
            v1.setEnabled(v0);
            if (this.f.clickTimestamp > v6) {
                com.ss.android.article.base.feature.detail2.config.a.b(v4, this.m, this.z.getColor(com.ss.android.article.browser.R.color.bx));
                return;
            }

            com.ss.android.article.base.feature.detail2.config.a.b(v4, this.m, this.z.getColor(com.ss.android.article.browser.R.color.ssxinzi1));
        }
    }

    protected void b(View arg23) {
        JSONObject v10;
        long v6;
        int v17;
        long v20;
        long v18;
        e v16;
        if (arg23 != null) {
            Object v3 = null;
            try {
                Object v2_1 = arg23.getTag();
                if ((v2_1 instanceof e)) {
                    v16 = (com.ss.android.article.base.feature.detail2.video.a.e) v2_1;
                } else {
                    v16 = null;
                }
                if (v16 == null) {
                    return;
                }

                if (v16.f == null) {
                    return;
                }

                if (v16.f.groupId <= 0) {
                    return;
                }


                v18 = v16.f.groupId;
                v20 = v16.f.itemId;
                v17 = v16.f.aggrType;
                v16.f.clickTimestamp = System.currentTimeMillis();
                v16.m.setSelected(false);
                if (v16.f.clickTimestamp > 0) {
                    v16.m.setTextColor(this.z.getColorStateList(com.ss.android.article.browser.R.color.bx));
                }

                v6 = 0;
                if (v16.f.ao != null && v16.f.ao.adId > 0) {
                    v6 = v16.f.ao.adId;
                }

                if (this.H <= 0) {
                } else {
                    try {
                        new JSONObject().put("from_gid", this.H);
                    } catch (JSONException v2_2) {
                    }
                }
                String v2_3 = v16.f.outerSchema;
                if (!android.support.design.a.isTextEmpty(v2_3) && (AppUtil.b(this.g, "com.youku.phone", v2_3))) {
                    AppUtil.b(this.g, v2_3);
                    MobClickCombiner.onEvent(this.g, "detail", "enter_youku");
                    return;
                }

                if (v16.f.ao.adId <= 0) {
                    MobClickCombiner.onEvent(this.g, "detail", "click_related_video", this.H, 0);
                } else {
                    v10 = new JSONObject();
                    try {
                        String v3_1 = "log_extra";
                        v2_3 = TextUtils.isEmpty(this.k) ? "{}" : this.k;
                        v10.put(v3_1, v2_3);
                    } catch (JSONException v2_2) {
                    }
                    v16.f.aG = this.k;
                    MobAdClickCombiner.onAdEvent(this.g, "embeded_ad", "click", v6, 0, v10, 2);
                }
                if (a(arg23, v16.f, "video")) {
                    return;
                }

                if (((this.g instanceof com.ss.android.article.base.feature.detail2.cc)) && (((com.ss.android.article.base.feature.detail2.cc) this.g).a(this.f))) {
                    return;
                }

                if (!android.support.design.a.isTextEmpty(this.f.openPageUrl)) {
                    AppUtil.b(this.g, AdsAppBaseActivity.b(v16.f.openPageUrl));
                    return;
                }

                if (!android.support.design.a.isTextEmpty(this.f.openUrl)) {
                    AppUtil.b(this.g, AdsAppBaseActivity.b(v16.f.openUrl));
                    return;
                }

                Intent v2_4 = new Intent(this.g, NewDetailActivity.class);
                v2_4.putExtra("view_single_id", true);
                v2_4.putExtra("group_id", v18);
                v2_4.putExtra("item_id", v20);
                v2_4.putExtra("aggr_type", v17);
                v2_4.putExtra("detail_source", "click_related");
                v2_4.putExtra("group_flags", v16.f.groupFlags);
                if (v6 > 0) {
                    v2_4.putExtra("ad_id", v6);
                }

                if (android.support.design.a.b(((long) v16.f.groupFlags))) {
                    v2_4.setClass(this.g, NewVideoDetailActivity.class);
                }

                if (this.H > 0) {
                    v2_4.putExtra("from_gid", this.H);
                }

                this.g.startActivity(v2_4);
            } catch (Throwable v2) {
                label_93:
                v2.printStackTrace();
            }
        }
    }

    protected final void c() {
        Object v0_2;
        ImageInfo v1_1;
        int v6;
        ImageInfo v5 = null;
        int v12 = 2;
        int v11 = 8;
        UIUtils.setVisibility(this.s, v11);
        UIUtils.setVisibility(this.o, v11);
        UIUtils.setVisibility(this.u, v11);
        UIUtils.setVisibility(this.c, v11);
        UIUtils.setVisibility(this.d, v11);
        if (this.f != null && (this.f.i())) {
            AppData.isNightMode();
            boolean[] v7 = new boolean[3];
            Article v4 = this.f;
            int v8 = this.y.mLoadImagePref;
            boolean v9 = this.A.isWifiOn();
            boolean v10 = this.A.isNetworkOn();
            if (v4.largeImageList != null) {
                int v0 = this.C * v4.largeImageList.mHeight / v4.largeImageList.mWidth;
                v6 = v0 > this.B ? this.B : v0;
            } else {
                v6 = 0;
            }

            boolean v0_1 = v6 <= 0 ? false : true;
            boolean v1 = v4.imageList == null || (v4.imageList.isEmpty()) ? false : true;
            boolean v4_1 = v4.middleImage == null ? false : true;
            if (!v9) {
                if ((v10) && v8 == 1) {
                    if (v0_1) {
                        v1 = false;
                        v4_1 = v0_1;
                        v0_1 = false;
                    } else if (v1) {
                        v4_1 = v0_1;
                        v0_1 = false;
                    } else {
                        boolean v13 = v4_1;
                        v4_1 = v0_1;
                        v0_1 = v13;
                    }
                } else if (!v10) {
                    if (v1) {
                        v0_1 = false;
                        v4_1 = false;
                    } else {
                        v0_1 = v4_1;
                        v4_1 = false;
                    }
                } else if (v4_1) {
                    v0_1 = v4_1;
                    v1 = false;
                    v4_1 = false;
                } else if (v1) {
                    v0_1 = true;
                    v1 = false;
                    v4_1 = false;
                } else {
                    v0_1 = v4_1;
                    v4_1 = false;
                }
            } else {
                label_189:
                if (v0_1) {
                    v1 = false;
                    v4_1 = v0_1;
                    v0_1 = false;
                } else if (v1) {
                    v4_1 = v0_1;
                    v0_1 = false;
                } else {
                    boolean v13 = v4_1;
                    v4_1 = v0_1;
                    v0_1 = v13;
                }
            }

            label_62:
            v7[0] = v4_1;
            v7[1] = v1;
            v7[v12] = v0_1;
            boolean v8_1 = v7[0];
            v0_1 = v7[1];
            boolean v7_1 = v7[v12];
            if (v8_1) {
                UIUtils.setVisibility(this.s, 0);
                a(this.t, 0, v6);
                v1_1 = this.f.largeImageList;
                this.t.setImageResource(com.ss.android.article.browser.R.drawable.cn);
                this.t.setTag(com.ss.android.article.browser.R.id.image_info, v1_1);
                Drawable v1_2 = this.t.getBackground();
                if (v1_2 != null) {
                    v1_2.setLevel(0);
                }
            }

            if ((v0_1) && this.f.imageList != null && !this.f.imageList.isEmpty()) {
                UIUtils.setVisibility(this.o, 0);
                v6 = this.f.imageList.size();
                v0_2 = this.f.imageList.get(0);
                Object v4_2 = v0_2 == null || v6 <= 1 ? v5 : this.f.imageList.get(1);
                if (v4_2 == null || v6 <= v12) {
                    v1_1 = v5;
                } else {
                    v1_1 = (ImageInfo) this.f.imageList.get(v12);
                }

                a(this.p, ((ImageInfo) v0_2));
                a(this.q, ((ImageInfo) v4_2));
                a(this.r, v1_1);
            }

            ImageInfo v0_3 = this.f.middleImage;
            if (v0_3 == null && this.f.imageList != null && !this.f.imageList.isEmpty()) {
                v0_2 = this.f.imageList.get(0);
            }

            if (!v7_1 || v0_3 == null) {
                if ((this.f.h()) && (v8_1)) {
                    UIUtils.setVisibility(this.d, 0);
                    if (this.f.videoDuration > 0) {
                        this.d.setText(ArticleHelper.convert2ReadableString(this.f.videoDuration), true);
                    } else {
                        this.d.setText("", false);
                        this.d.a(com.ss.android.article.base.feature.app.a.b.i, true);
                    }
                }

                this.G = false;
            } else {
                UIUtils.setVisibility(this.u, 0);
                if (this.f.h()) {
                    UIUtils.setVisibility(this.c, 0);
                    UIUtils.setVisibility(this.w, v11);
                    UIUtils.setVisibility(this.v, 0);
                    UIUtils.setVisibility(this.e, 0);
                    if (this.f.videoDuration > 0) {
                        this.c.setText(ArticleHelper.convert2ReadableString(this.f.videoDuration), true);
                    } else {
                        this.c.setText("", false);
                        this.c.a(com.ss.android.article.base.feature.app.a.b.i, true);
                    }

                    if (this.I == a) {
                        this.e.setText(UIUtils.a(this.f.videoWatchCount) + this.g.getString(com.ss.android.article.browser.R.string.video_play_prefix));
                    } else {
                        this.e.setText(UIUtils.a(this.f.commentCount) + this.g.getString(com.ss.android.article.browser.R.string.comment_prefix));
                    }

                    this.v.setText(this.f.source);
                    if (android.support.design.a.isTextEmpty(this.j)) {
                    } else {
                        UIUtils.setVisibility(this.J, 0);
                        this.J.setText(this.j);
                    }
                }

                a(this.u, v0_3);
                this.G = true;
            }

            if (this.G) {
                return;
            }

            this.a();
        }
    }

    protected final void d() {
        int v0 = this.y.mFontSizePref;
        if (v0 < 0 || v0 > 3) {
            v0 = 0;
        }

        this.m.setTextSize(((float) l[v0]));
    }

    public final void e() {
        int v10 = R.drawable.palyicon_video_textpage;
        int v9 = 3;
        int v6 = R.color.t;
        if (this.F != AppData.isNightMode()) {
            this.F = AppData.isNightMode();
            boolean v0 = this.F;
            ClickableBackgroundCompat.setClickableBackground(this.b, v0);
            if (this.f.clickTimestamp > 0) {
                com.ss.android.article.base.feature.detail2.config.a.b(v9, this.m, this.z.getColor(com.ss.android.article.browser.R.color.bx));
            } else {
                com.ss.android.article.base.feature.detail2.config.a.b(v9, this.m, this.z.getColor(com.ss.android.article.browser.R.color.ssxinzi1));
            }

            this.n.setImageResource(com.ss.android.article.browser.R.color.hh);
            this.v.setTextColor(this.z.getColorStateList(com.ss.android.article.browser.R.color.ssxinzi3));
            this.J.setTextColor(this.z.getColorStateList(com.ss.android.article.browser.R.color.update_comment_more_text_selector));
            this.J.setBackgroundResource(com.ss.android.article.browser.R.drawable.related_album_lable_bg);
            this.e.setTextColor(this.z.getColorStateList(com.ss.android.article.browser.R.color.ssxinzi3));
            UIUtils.setBackgroundResource(this.w, R.drawable.detail_related_video_small_icon);
            UIUtils.setBackgroundResource(this.t, R.drawable.simple_image_holder_listpage);
            UIUtils.setBackgroundResource(this.p, v6);
            UIUtils.setBackgroundResource(this.q, v6);
            UIUtils.setBackgroundResource(this.r, v6);
            UIUtils.setBackgroundResource(this.u, v6);
            this.c.a(ContextCompat.getColorStateList(this.g, R.color.ssxinzi12), false);
            this.c.setDrawable(ContextCompat.getDrawable(this.g, v10), true);
            this.c.setBackgroundResource(com.ss.android.article.browser.R.drawable.video_time_length_bg);
            this.d.a(ContextCompat.getColorStateList(this.g, R.color.ssxinzi12), false);
            this.d.setDrawable(ContextCompat.getDrawable(this.g, v10), true);
            this.d.setBackgroundResource(com.ss.android.article.browser.R.drawable.video_time_length_bg);
            ColorFilter v0_1 = v0 ? TTUtils.getNightModeColorFilter() : null;
            this.t.setColorFilter(v0_1);
            this.u.setColorFilter(v0_1);
            this.p.setColorFilter(v0_1);
            this.q.setColorFilter(v0_1);
            this.r.setColorFilter(v0_1);
        }
    }

    protected final void f() {
        int v0 = this.G ? ((int) this.z.getDimension(R.dimen.fo)) : 0;
        this.m.setPadding(0, 0, v0, 0);
    }
}

